package com.situation.controller;

import com.situation.annotation.ControllerEndpoint;
import com.situation.pojo.DO.BizProduct;
import com.situation.service.impl.BizProductServiceImpl;
import com.situation.util.RespUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * @author: 羽程
 * @create: 2021-12-07 19:49
 **/
@RestController
@RequestMapping("/api/product")
public class BizProductController {
    @Autowired
    private BizProductServiceImpl bizProductService;

    @ControllerEndpoint(exceptionMessage = "添加物资信息失败",operation = "添加物资信息")
    @RequestMapping("/add")
    @RequiresPermissions({"product:add"})
    public RespUtil insertProduct(BizProduct bizProduct){
        return RespUtil.ok().setData(bizProductService.insertProduct(bizProduct));
    }

    @ControllerEndpoint(exceptionMessage = "恢复物资失败",operation = "恢复物资")
    @RequestMapping("/back")
    @RequiresPermissions({"product:back"})
    public RespUtil back(BizProduct bizProduct){
        return RespUtil.ok().setData(bizProductService.back(bizProduct));

    }

    @ControllerEndpoint(exceptionMessage = "添加物资审核失败",operation = "添加物资审核")
    @RequestMapping("/publish")
    @RequiresPermissions({"product:publish"})
    public RespUtil publish(BizProduct bizProduct){
        return RespUtil.ok().setData(bizProductService.back(bizProduct));
    }

    @ControllerEndpoint(exceptionMessage = "物资移入回收站失败",operation = "物资移入回收站")
    @RequestMapping("/remove/{id}")
    @RequiresPermissions({"product:remove"})
    public RespUtil remove(@PathVariable Long id){
        BizProduct bizProduct=new BizProduct();
        bizProduct.setId(id);
        return RespUtil.ok().setData(bizProductService.remove(bizProduct));
    }

    @ControllerEndpoint(exceptionMessage = "删除物资失败",operation = "删除物资")
    @RequestMapping("/delete")
    @RequiresPermissions({"product:delete"})
    public RespUtil delete(BizProduct bizProduct){
        return RespUtil.ok().setData(bizProductService.delete(bizProduct));
    }

    /**
     * 编辑物资信息的数据回填
     * @param bizProduct
     * @return
     */
    @RequestMapping("/edit")
    @RequiresPermissions({"product:edit"})
    public RespUtil edit(BizProduct bizProduct){
        return RespUtil.ok().setData(bizProductService.findBizProductById(bizProduct));
    }

    /**
     * 编辑物资信息
     */
    @ControllerEndpoint(exceptionMessage = "更新物资信息失败",operation = "更新物资信息")
    @RequestMapping("/update")
    @RequiresPermissions({"product:update"})
    public RespUtil update(BizProduct bizProduct){
        return RespUtil.ok().setData(bizProductService.update(bizProduct));
    }


    /**
     * 查询所有物资库存信息
     */
    @RequestMapping("/findAllStocks")
    public RespUtil findAllStocks(BizProduct bizProduct,int pageNum,int pageSize){
        return RespUtil.ok().setData(bizProductService.findAllStocks(bizProduct,pageNum,pageSize));
    }

    /**
     * 多条件查询+通过姓名模糊查询
     * @param bizproduct
     * @return
     */
    @RequestMapping("/findProductList")
    public RespUtil findProductList(BizProduct bizproduct ,int pageNum,int pageSize){
        return RespUtil.ok().setData(bizProductService.findProductList(bizproduct,pageNum,pageSize));
    }

    /**
     * 查询可入库物资列表 多条件+通过姓名模糊
     * @param bizproduct
     * @return
     */
    @RequestMapping("/findProducts")
    public RespUtil findProducts(BizProduct bizproduct,int pageNum,int pageSize){
        return RespUtil.ok().setData(bizProductService.findProductList(bizproduct,pageNum,pageSize));
    }

}
